package com.xy.etl.ibatis.node.impl;

import com.xy.etl.ibatis.core.XySQLExePara;
import com.xy.etl.ibatis.core.XySQLKit;
import com.xy.etl.ibatis.core.XySQLTaskContext;
import com.xy.etl.ibatis.itf.XySQLRegister;
import com.xy.etl.ibatis.node.XySQLSuperNode;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
@Slf4j
public class XySQLIfNode extends XySQLSuperNode {

    @Override
    public String getTag() {
        return "if";
    }

    @Override
    public XySQLSuperNode clone() {
        return new XySQLIfNode();
    }

    private static final String IF_ATT_COND = "test";

    private String newCond = null;

    public List<XySQLExePara> boundSql(XySQLTaskContext task) throws Exception {
        if (newCond == null) {
            newCond = this.getPropertyMap().get(IF_ATT_COND);
        }
        if (XySQLKit.runPredicate(newCond, task)) {
            List<XySQLExePara> res = super.boundSql(task);
            return res;
        } else {
            log.debug("if 公式(" + newCond + "),执行结果:false ");
        }
        return new ArrayList<>();
    }
}
